Imports System.Security
Imports System.Threading
Imports AppliedRecognition.Util
Imports System.Collections.Specialized

Module AppEntry
    Public Sub Main()
        Dim msg As String = ""
        Try

            Threading.Thread.CurrentThread.Name = "QuickSwichMainAppThread"

            Dim c As New QuickSwitchConfig

            Dim ehc As Util.ExceptionHandlerConfig = Util.ExceptionHandlerConfig.Instance
            With ehc
                .LogToEventLog = True
                .IgnoreDebug = False 'c.IgnoreDebug
                .TakeScreenshot = True
                .KillAppOnException = False
                .DisplayDialog = True
                .LogToFile = True
                .DebugDirectory = c.DebugDataPath
            End With
            UnhandledExceptionManager.AddHandler()
            UnhandledExceptionManager.AdditionalInfo = AddressOf DNS.DNSVersionString

            c.EnableTracing()



            Dim cd As New CommandDispatch

            If Not CommandDispatch.FirstSystemInstance Then
                MsgBox("QuickSwitch is already loaded.", MsgBoxStyle.Information, "QuickSwitch")
                Exit Sub
            End If



            If My.MySettings.Default.SplashScreenDuration > 0 Then
                Dim img As New Bitmap(QSRes.SplashScreenImage)
                SplashScreen.BackImage = img
                SplashScreen.ShowSplashScreen()
                Application.DoEvents()
            End If


            If Environment.CurrentDirectory <> Application.StartupPath Then
                Environment.CurrentDirectory = Application.StartupPath
            End If

            Application.Run(cd)
            Trace.Write("QS Exit")
            Trace.Flush()




            Catch ex As IO.FileNotFoundException
            msg += "Unable to find file '" + ex.FileName + "'" + vbNewLine
            msg += "Please repair the installation." + vbNewLine
            msg += "Technical details below" + vbNewLine
            msg += "==========================================" + vbNewLine
            msg += ex.ToString
            MsgBox(msg, MsgBoxStyle.Critical, "QuickSwitch Fatal error")
            Exit Sub
        Catch ex As SecurityException
            msg += "Unable to run the application with current security settings." + vbNewLine
            msg += "Most commonly, this is due to attempting to run from a networked location." + vbNewLine
            msg += "Please reinstall to a local drive or adjust your security configuration."
            MsgBox(msg, MsgBoxStyle.Critical, "QuickSwitch Fatal error")
            Exit Sub
        Finally
            Trace.Flush()
        End Try
    End Sub


End Module

